
package com.huizhan.web.controller;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.*;
import java.util.*;

import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;

/**
 * 订单项api
 */
 
@Api(tags = "OrderItem",description = "订单项")
@RestController
public class OrderItemController {
    
    @Autowired
    private OrderItemDao dao;
   
    /**
     * 获取订单项集合
     * @return api结果
     */
    @ApiOperation(value = "获取订单项集合")
    @RequestMapping(value =  "/api/OrderItem/",method = {RequestMethod.GET})
    public ApiResult<List<OrderItem>> Get(){
         ApiResult<List<OrderItem>> result=new ApiResult<List<OrderItem>>();
        try 
        {
            List<OrderItem> res = dao.findAll();
            result.setData(res);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据订单ID获取订单详情
     * @param OrderFormId 订单ID
     * @return api结果
     */
    @ApiOperation(value = "根据订单ID获取订单详情")
    @RequestMapping(value =  "/api/OrderItem/OrderForm/{orderFormId}",method = {RequestMethod.GET})
    public ApiResult<List<OrderItem>> Phone(@PathVariable Long orderFormId){
        ApiResult<List<OrderItem>> result=new ApiResult<List<OrderItem>>();
        try
        {
            List<OrderItem> model= dao.findByOrderFormId(orderFormId);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据ID获取订单项信息
     * @param id 订单项ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取订单项信息")
    @RequestMapping(value =  "/api/OrderItem/{id}",method = {RequestMethod.GET})
    public ApiResult<OrderItem> Get(@PathVariable Long id){
        ApiResult<OrderItem> result=new ApiResult<OrderItem>();
        try
        {
            OrderItem model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 修改订单项信息
     * @param id 订单项ID
     * @param model 订单项信息
     * @return api结果
     */
    @ApiOperation(value = "修改订单项信息")
    @RequestMapping(value =  "/api/OrderItem/{id}",method = {RequestMethod.PUT})
    public ApiResult<OrderItem> Edit(@PathVariable Long id,@RequestBody OrderItem model){
        ApiResult<OrderItem> result=new ApiResult<OrderItem>();
        try
        {
            model.setOrderItemId(id);
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 添加订单项信息
     * @param model 订单项信息
     * @return api结果
     */
    @ApiOperation(value = "添加订单项信息")
    @RequestMapping(value =  "/api/OrderItem/",method = {RequestMethod.POST})
    public ApiResult<OrderItem> Add(@RequestBody OrderItem model){
         ApiResult<OrderItem> result=new ApiResult<OrderItem>();
        try
        {
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除订单项信息
     * @param id 订单项ID
     * @return api结果
     */
    @ApiOperation(value = "删除订单项信息")
    @RequestMapping(value =  "/api/OrderItem/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

